package com.accloud.cloudservice;

import com.accloud.service.Receiver;

/* access modifiers changed from: package-private */
public class ListenTask {
    private boolean cancel;
    private final int interval_ms;
    private final Receiver<LocalMessage> listener;
    private final int timeout_ms;

    public ListenTask(int timeout_ms2, int interval_ms2, Receiver<LocalMessage> listener2) {
        this.timeout_ms = timeout_ms2;
        this.interval_ms = interval_ms2;
        this.listener = listener2;
    }

    public void execute(final VoidCallback callback) {
        new Thread() {
            /* class com.accloud.cloudservice.ListenTask.AnonymousClass1 */

            /* JADX WARNING: Removed duplicated region for block: B:22:0x007c  */
            /* JADX WARNING: Removed duplicated region for block: B:27:0x0088  */
            /* JADX WARNING: Removed duplicated region for block: B:30:0x008f  */
            /* JADX WARNING: Removed duplicated region for block: B:32:0x0093  */
            @Override // java.lang.Thread, java.lang.Runnable
            /* Code decompiled incorrectly, please refer to instructions dump. */
            public void run() {
                /*
                    r12 = this;
                    r8 = 84
                    byte[] r0 = new byte[r8]
                    java.net.DatagramPacket r2 = new java.net.DatagramPacket
                    int r8 = r0.length
                    r2.<init>(r0, r8)
                    r4 = 0
                    java.net.DatagramSocket r5 = new java.net.DatagramSocket     // Catch:{ IOException -> 0x0082 }
                    r8 = 8689(0x21f1, float:1.2176E-41)
                    r5.<init>(r8)     // Catch:{ IOException -> 0x0082 }
                    com.accloud.cloudservice.ListenTask r8 = com.accloud.cloudservice.ListenTask.this     // Catch:{ IOException -> 0x00a5, all -> 0x00a2 }
                    int r8 = com.accloud.cloudservice.ListenTask.access$000(r8)     // Catch:{ IOException -> 0x00a5, all -> 0x00a2 }
                    r5.setSoTimeout(r8)     // Catch:{ IOException -> 0x00a5, all -> 0x00a2 }
                    long r6 = java.lang.System.currentTimeMillis()     // Catch:{ IOException -> 0x00a5, all -> 0x00a2 }
                L_0x001f:
                    long r8 = java.lang.System.currentTimeMillis()     // Catch:{ IOException -> 0x00a5, all -> 0x00a2 }
                    long r8 = r8 - r6
                    com.accloud.cloudservice.ListenTask r10 = com.accloud.cloudservice.ListenTask.this     // Catch:{ IOException -> 0x00a5, all -> 0x00a2 }
                    int r10 = com.accloud.cloudservice.ListenTask.access$100(r10)     // Catch:{ IOException -> 0x00a5, all -> 0x00a2 }
                    long r10 = (long) r10     // Catch:{ IOException -> 0x00a5, all -> 0x00a2 }
                    int r8 = (r8 > r10 ? 1 : (r8 == r10 ? 0 : -1))
                    if (r8 >= 0) goto L_0x0069
                    r8 = 1
                    r9 = r8
                L_0x0031:
                    com.accloud.cloudservice.ListenTask r8 = com.accloud.cloudservice.ListenTask.this     // Catch:{ IOException -> 0x00a5, all -> 0x00a2 }
                    boolean r8 = com.accloud.cloudservice.ListenTask.access$200(r8)     // Catch:{ IOException -> 0x00a5, all -> 0x00a2 }
                    if (r8 != 0) goto L_0x006c
                    r8 = 1
                L_0x003a:
                    r8 = r8 & r9
                    if (r8 == 0) goto L_0x006e
                    r5.receive(r2)     // Catch:{ SocketTimeoutException -> 0x0067, ACException -> 0x00a8 }
                    int r8 = r2.getLength()     // Catch:{ SocketTimeoutException -> 0x0067, ACException -> 0x00a8 }
                    java.nio.ByteBuffer r8 = java.nio.ByteBuffer.allocate(r8)     // Catch:{ SocketTimeoutException -> 0x0067, ACException -> 0x00a8 }
                    byte[] r9 = r2.getData()     // Catch:{ SocketTimeoutException -> 0x0067, ACException -> 0x00a8 }
                    r10 = 0
                    int r11 = r2.getLength()     // Catch:{ SocketTimeoutException -> 0x0067, ACException -> 0x00a8 }
                    java.nio.ByteBuffer r8 = r8.put(r9, r10, r11)     // Catch:{ SocketTimeoutException -> 0x0067, ACException -> 0x00a8 }
                    byte[] r3 = r8.array()     // Catch:{ SocketTimeoutException -> 0x0067, ACException -> 0x00a8 }
                    com.accloud.cloudservice.ListenTask r8 = com.accloud.cloudservice.ListenTask.this     // Catch:{ SocketTimeoutException -> 0x0067, ACException -> 0x00a8 }
                    com.accloud.service.Receiver r8 = com.accloud.cloudservice.ListenTask.access$300(r8)     // Catch:{ SocketTimeoutException -> 0x0067, ACException -> 0x00a8 }
                    com.accloud.cloudservice.LocalMessage r9 = com.accloud.cloudservice.LocalMessage.fromBytes(r3)     // Catch:{ SocketTimeoutException -> 0x0067, ACException -> 0x00a8 }
                    r8.onReceive(r9)     // Catch:{ SocketTimeoutException -> 0x0067, ACException -> 0x00a8 }
                    goto L_0x001f
                L_0x0067:
                    r8 = move-exception
                    goto L_0x001f
                L_0x0069:
                    r8 = 0
                    r9 = r8
                    goto L_0x0031
                L_0x006c:
                    r8 = 0
                    goto L_0x003a
                L_0x006e:
                    if (r5 == 0) goto L_0x00ab
                    r5.close()
                    r4 = r5
                L_0x0074:
                    com.accloud.cloudservice.ListenTask r8 = com.accloud.cloudservice.ListenTask.this
                    boolean r8 = com.accloud.cloudservice.ListenTask.access$200(r8)
                    if (r8 == 0) goto L_0x0093
                    com.accloud.cloudservice.VoidCallback r8 = r2
                    r8.success()
                L_0x0081:
                    return
                L_0x0082:
                    r1 = move-exception
                L_0x0083:
                    r1.printStackTrace()     // Catch:{ all -> 0x008c }
                    if (r4 == 0) goto L_0x0074
                    r4.close()
                    goto L_0x0074
                L_0x008c:
                    r8 = move-exception
                L_0x008d:
                    if (r4 == 0) goto L_0x0092
                    r4.close()
                L_0x0092:
                    throw r8
                L_0x0093:
                    com.accloud.cloudservice.VoidCallback r8 = r2
                    com.accloud.service.ACException r9 = new com.accloud.service.ACException
                    int r10 = com.accloud.service.ACException.TIMEOUT
                    java.lang.String r11 = "Listen local message timeout"
                    r9.<init>(r10, r11)
                    r8.error(r9)
                    goto L_0x0081
                L_0x00a2:
                    r8 = move-exception
                    r4 = r5
                    goto L_0x008d
                L_0x00a5:
                    r1 = move-exception
                    r4 = r5
                    goto L_0x0083
                L_0x00a8:
                    r8 = move-exception
                    goto L_0x001f
                L_0x00ab:
                    r4 = r5
                    goto L_0x0074
                */
                throw new UnsupportedOperationException("Method not decompiled: com.accloud.cloudservice.ListenTask.AnonymousClass1.run():void");
            }
        }.start();
    }

    public void cancel() {
        this.cancel = true;
    }
}
